package myapp.com.xm.myapplication;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;

import com.xm.httpapi.Annotation.ViewL;
import com.xm.httpapi.BaseView.BaseActivity;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import myapp.com.xm.myapplication.Adapter.Adapter;

@ViewL(R.layout.list)
public class ListActivity extends BaseActivity {
    private RecyclerViewP recyclerView;
    private Adapter adapter;

    @Override
    protected void initData(Bundle savedInstanceState) {
        EventBus.getDefault().register(this);
        recyclerView = findViewById(R.id.list);
        adapter = new Adapter(this);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);


        recyclerView.addOnScrollListener(new OnVerticalScrollListener() {
            //上滑到固定位置把事件给子view
            @Override
            public void onScrolledUp(int firstPos, int total) {
                super.onScrolledUp(firstPos, total);
                if (firstPos == total - 2) {
                    recyclerView.interceptsonView(false);
                }
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected String showTitle() {
        return "列表";
    }


    String message;

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onGetMessage(String message) {
        this.message = message;
        if("0".equals(message)){
            recyclerView.interceptsonView(true);
        }
    }


}
